# -*- coding: utf-8 -*-

from gtk import *
from includes import *

class PhotoList(GenericTreeModel):
	
	column_types = (gdk.Pixbuf, str, str, int, int, int, str, gdk.Pixbuf,int,int)
	
	def __init__(self):
		GenericTreeModel.__init__(self)
		self.list = []
	
	def on_get_flags(self):
		return TREE_MODEL_LIST_ONLY#|TREE_MODEL_ITERS_PERSIST
		
	def on_get_n_columns(self):
		return len(self.column_types)
		
	def on_get_column_type(self, index):
		return self.column_types[index]
		
	def on_get_iter(self, path):
		try:
		    return self.list[path[0]]
		except IndexError:
		    return None
		    
	def on_get_path(self, rowref):
		return self.list.index(rowref)
		
	def on_get_value(self, rowref, column):
		if column is COLUMN_THUMB:
			return rowref.thumb
		elif column is COLUMN_NAME:
			return rowref.name
		elif column is COLUMN_TYPE:
			return rowref.type
		elif column is COLUMN_WIDTH:
			return rowref.width
		elif column is COLUMN_HEIGHT:
			return rowref.height
		elif column is COLUMN_X:
			return rowref.width
		elif column is COLUMN_Y:
			return rowref.height
		elif column is COLUMN_NB_COPY:
			return rowref.nb_copy
		elif column is COLUMN_NB_COPY_TEXT:
			if rowref.nb_copy == 0:
				return "<span size=\"large\">aucune impression</span>"
			elif rowref.nb_copy == 1:
				return "<span size=\"large\"><span foreground=\"blue\" weight=\"bold\" size=\"larger\">1</span> impression</span>"
			else :
				return "<span size=\"large\"><span foreground=\"blue\" weight=\"bold\" size=\"larger\">" + str(rowref.nb_copy) + "</span> impressions</span>"
		elif column is COLUMN_PIXBUF:
			return rowref.pixbuf
			
	def on_iter_next(self, rowref):
		try:
		    return self.list[self.list.index(rowref) + 1]
		except IndexError:
		    return None
		    
	def on_iter_children(self, rowref):
		if rowref:
		    return None
		try:
		    return self.list[0]
		except IndexError:
		    return None
		    
	def on_iter_has_child(self, rowref):
		return False
		
	def on_iter_n_children(self, rowref):
		if rowref:
		    return 0
		return len(self.list)
		
	def on_iter_nth_child(self, parent, n):
		if rowref:
		    return None
		try:
		    return self.list[n]
		except IndexError:
		    return None
		    
	def on_iter_parent(self, child):
		return None
	
	def append(self, rowref):
		self.list.append(rowref)
		path = (self.list.index(rowref),)
            	iter = self.get_iter(path)
		self.row_inserted(path, iter)
		
	def remove(self, path):
		del self.list[path[0]]
		self.row_deleted(path)
		
	def insert(self, pos, rowref):
		self.list.insert(pos, rowref)
		path = (pos,)
            	iter = self.get_iter(path)
		self.row_inserted(path, iter)
	
	def get(self, path):
		return self.list[path]
	
	def get_nb_photo(self):
		return sum(p.nb_copy for p in self.list)
			
	
